<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%
    request.setCharacterEncoding("UTF-8");
    String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : "";
%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/JSP/backHome/modalWindows/StudentsListDropexerciseThree.jsp" %>
<%@ include file="/WEB-INF/JSP/backHome/modalWindows/CartimeListPage.jsp" %>
<%@ include file="/WEB-INF/JSP/backHome/modalWindows/Sub.jsp" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script type="text/javascript" src="<%=path%>/My97DatePicker/WdatePicker.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=path%>/CSS/backLayout.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/CSS/bombBox.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/RightAndLeftWitchPage/style.css">
</head>
<style>
    select {
        width: 234px;
        height: 31px
    }

    .tr td {
        font-size: 14px;
        color: #ffffff
    }

    .tr_td {
        height: 40px;
    }

    .tr_td td {
        border-bottom: 1px solid #ededed;
        text-align: center;
    }

    tr td:nth-child(1) {
        font-size: 14px;
        color: #cccccc
    }

    .date {
        border: 0;
        background: #ffffff;
        text-align: center;
    }

    .tr_td td:nth-child(1) {
        border-left: 1px solid #cccccc;
    }

    .tr_td td:nth-child(3) {
        border-right: 1px solid #cccccc;
    }

    .addTable.deleteTable:HOVER {
        cursor: pointer;
    }

    type[type='checkbox'] {
        width: 15px
    }

    .input_hang {
        width: 380px;
        height: 40px;
    }

    .input_hang2 {
        width: 450px;
        height: 40px;
    }

    .input_hang input {
        width: 185px;
        height: 30px;
        line-height: 30px;
        border: solid 1px #cccccc;
    }

    .input_hang .gn_name {
        line-height: 30px;
        height: 30px;
    }

    .right_hang {
        padding-top: 90px;
        padding-left: 170px;
        width: 800px;
        height: 60px;
    }

    .modal-data3 td {
        padding-left: 15px;
        padding-right: 15px;
        font-size: 16px;
        color: black;
    }

    .subtn2, .btn {
        margin-top: 20px;
    }

    .input_hang select {
        width: 185px;
    }

    .input_fname2 {
        -moz-user-select: none; /*火狐*/
        -webkit-user-select: none; /*webkit浏览器*/
        -ms-user-select: none; /*IE10*/
        -khtml-user-select: none; /*早期浏览器*/
        user-select: none;
        cursor: pointer;
    }

    .page ul {
        margin-top: 10px;
    }

    li span {
        font-size: 16px;
    }

    .cartimeName {
        width: 120px;
        border: 1px solid #ccc;
    }

    .head {
        height: 50px;
        line-height: 50px;
        margin-top: 20px;
        font-size: 20px;
    }

    .box {
        width: 250px;
        float: left;
        text-align: center;
        height: 100px;
    }

    .err_msr {
        width: 500px;
        height: 30px;
        float: left;
        line-height: 30px;
        text-align: center;
    }

    .fc_name span {
        display: block;
        width: 250px;
        text-align: center;
        float: left;
    }

    .error {
        color: #ff5046;
    }

    .weizhi {
        margin-top: 10px;
    }
</style>
<body style="background: #f5f5f5">
<div class="main">
    <div id="modal-overlay">

    </div>
    <div class="weizhi">
        练车管理>>科目二/三自动分车
    </div>
    <div class="div_body" style="box-shadow: 0 0 5px #cccccc;">

        <div class="div_form">
                <div class="input_hang">
                    <div class="input_hang">
                        <span class="gn_name">练车时间&nbsp;:&nbsp;</span>
                        <input name="cfdycs" class="is_click" value="" style="color: gray;"
                               onclick="clicklcsj($(this))"/>
                        <input type="hidden" class="cflcsjid" name="cflcsjid" value="" style="color: gray;"/>
                        <input type="hidden" class="cflcsjName" name="cflcsjName" value="" style="color: gray;"/>
                    </div>
                    <div class="input_hang">
                        <span class="gn_name">车型&nbsp;:&nbsp;</span>
                        <select onchange="selectPersonList()" class="carType">
                            <option style="color: gray;" value="A1">A1</option>
                            <option style="color: gray;" value="A2">A2</option>
                            <option style="color: gray;" value="A3">A3</option>
                            <option style="color: gray;" value="B1">B1</option>
                            <option style="color: gray;" value="B2">B2</option>
                            <option style="color: gray;" value="C1">C1</option>
                            <option style="color: gray;" value="C2">C2</option>
                            <option style="color: gray;" value="C3">C3</option>
                            <option style="color: gray;" value="C4">C4</option>
                            <option style="color: gray;" value="D">D</option>
                            <option style="color: gray;" value="E">E</option>
                            <option style="color: gray;" value="F">F</option>
                            <option style="color: gray;" value="M">M</option>
                            <option style="color: gray;" value="N">N</option>
                            <option style="color: gray;" value="P">P</option>
                        </select>
                    </div>
                </div>

                <div class="input_hang">
                    <div class="input_hang2">
                        <span class="gn_name">人数/车:&nbsp;&nbsp;</span>
                        <div class="well">
                            <div class="input-group spinner" data-trigger="spinner">
                                <input class="number" type="text" class="form-control text-center" value="0"
                                       data-rule="quantity">
                                <div class="input-group-addon">
                                    <a href="javascript:;" class="spin-up" data-spin="up"><i class="fa fa-caret-up"></i></a>
                                    <a href="javascript:;" class="spin-down" data-spin="down"><i
                                            class="fa fa-caret-down"></i></a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="input_hang">
                        <span class="gn_name">科目&nbsp;:&nbsp;</span>
                        <select onchange="selectPersonList()" class="kemu">
                            <option style="color: gray;" value="2">科目二</option>
                            <option style="color: gray;" value="3">科目三</option>

                        </select>
                    </div>
                </div>


                <div class="right_hang">
                    <div class="ty-transfer mt20 ml20" id="ued-transfer-1">
                        <div class="fl ty-transfer-list transfer-list-left">
                            <div class="ty-transfer-list-head">
                                未选教练
                            </div>

                            <div class="ty-transfer-list-body">
                                <ul class="ty-tree-select1">

                                </ul>
                            </div>
                            <div class="ty-transfer-list-foot">
                                <div class="ty-tree-div">
                                    <div class="tyc-check-blue fl">
                                        <input type="checkbox" class="transfer-all-check" id="tyc-check-blue">
                                        <span>
                    </span>
                                    </div>
                                    <div class="ty-tree-text">
                                        全选
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="fl ty-transfer-operation">
        <span class="ty-transfer-btn-toright to-switch">
        </span>
                            <span class="ty-transfer-btn-toleft to-switch">
        </span>
                        </div>
                        <div class="fl ty-transfer-list transfer-list-right">
                            <div class="ty-transfer-list-head">
                                已选教练
                            </div>
                            <div class="ty-transfer-list-body">
                                <ul class="ty-tree-select">

                                </ul>
                            </div>
                            <div class="ty-transfer-list-foot">
                                <div class="ty-tree-div">
                                    <div class="tyc-check-blue fl">
                                        <input type="checkbox" class="transfer-all-check" id="tyc-check-blue">
                                        <span>
                    </span>
                                    </div>
                                    <div class="ty-tree-text">
                                        全选
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="clearboth">
                        </div>
                    </div>

                    <div class="div_tj" style="margin-bottom: 200px; margin-top: 10px; margin-left: 115px;">
                        <div>
                            <input onclick="input_submit()" type="submit" class="input_submit" value="开   始">
                        </div>
                        <div>
                            <input type="button" class="input_back" value="返   回" onclick="back()"/>
                        </div>
                    </div>

                </div>

        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="<%=path%>/JQuery/jquery-1.8.2.js"></script>
<script type="text/javascript" src="<%=path%>/HoganJS/handlebars-v4.0.11.js"></script>
<script type="text/javascript" src="<%=path%>/RightAndLeftWitchPage/Transfer.js"></script>
<script id="table-template-jlList" type="text/x-handlebars-template">
    {{#each this}}
    <li>
        <div class="ty-tree-div">
            <label class="tyue-checkbox-wrapper">
                            <span class="tyue-checkbox">
                                <input class="cfcoachid" type="checkbox" class="tyue-checkbox-input"
                                       id="tyue-checkbox-blue" value="{{fid}}">
                                <span class="tyue-checkbox-circle">
                                </span>
                            </span>
                <span class="tyue-checkbox-txt" title="{{fnameL2}}">
                               <input class="input_fname2" name="fnameL2" value="{{fnameL2}}" readonly="readonly">
                            </span>
            </label>
        </div>
    </li>
    {{/each}}
</script>
<script id="table-template-msr" type="text/x-handlebars-template">
    <div class="head">分车结果</div>

    <div class="box">
        <div>此次分车成功人:</div>
        <div class="fc_name" style="overflow:scroll;">
            {{#each success.successName}}
            <span>{{this}}</span>
            {{/each}}
        </div>
    </div>

    <div class="box">
        <div>此次分车失败人:</div>

        <div class="fc_name error" style="overflow:scroll;">
            {{#each success.errorName}}
            <span>{{this}}</span>
            {{/each}}
        </div>
    </div>
    <div class="err_msr"> 失败原因：{{error.errMsr}}</div>
</script>
<script type="text/javascript">
    $('#ued-transfer-1').transferItem();

    var jlList = Handlebars.compile($("#table-template-jlList").html());
    var msr = Handlebars.compile($("#table-template-msr").html());

    function input_submit() {
        var cflcsjid = $('.cflcsjid').val();
        var cflcsjName=$('.is_click').val();//练车时间名称
        var carType = $('.carType').val();
        var number = $('.number').val();
        var kemu = $('.kemu').val();
        var cfcoachid = "";
        var cfcoach = $('.ty-tree-select .cfcoachid');
        for (var i = 0; i < cfcoach.length; i++) {
            cfcoachid += cfcoach[i].value + ","
        }
        var toCheck=cflcsjName.match(/科目(\S*)/)[1];
        if (cflcsjid == "") {
            alert("练车时间不能为空！");
            return false;
        }
        if (number == 0) {
            alert("人数不能为零！");
                alert(kemu)
                alert(toCheck)
            return false;
        }
        //判断科目几并将其转化成数字
         if(toCheck=="三"){
            if(kemu==2){
                alert("练车时间与科目不符")
                return false
            }
        }else if(toCheck=="二"){
             if(kemu==3){
                 alert("练车时间与科目不符")
                 return false
             }

         }

        /*if (cfcoachid == "") {
            alert("教练不能为空！");
            return false;
        }*/
        $.ajax({
            url: '<%=path%>/DrivingSys/addSharecarsubentry ',
            type: "post",
            data: {
                'cflcsjid': cflcsjid,
                'carType': carType,
                'number': number,
                'kemu': kemu,
                'cfcoachid': cfcoachid
            },
            dataType: "json",
            success: function (res) {
                $('#msr').html(msr(res));
                $('#modal-overlay').css('visibility', 'visible')
                $('.modal-data-sun').css('visibility', 'visible')
            },
            error: function () {
                alert('Error');
            }
        });
    }

    //返回
    function back() {
        location = '<%=path%>/DrivingSys/queryDropexercisethree/look.action?state=first';
    }

    //改变复选框的值
    function chcek() {

        var event = event || window.event;

        $("input[name=xyname]").each(function () {
            if ($(this).val() == "") {
                alert("学员姓名不能为空！")
                event.preventDefault(); // 兼容标准浏览器
                window.event.returnValue = false; // 兼容IE6~8
                return false;

            }
            else {

            }
        });

    }

    /* 关闭弹出框    */
    $('.btn').click(function () {
        $('#modal-overlay').css('visibility', 'hidden')
        $('.modal-data').css('visibility', 'hidden')
        $('.modal-data1').css('visibility', 'hidden')
        $('.modal-data2').css('visibility', 'hidden')
        $('.modal-data3').css('visibility', 'hidden')
        $('.modal-data-sun').css('visibility', 'hidden')
        $('.data-checkbox:checkbox').removeAttr('checked');
        $('.data1-checkbox:checkbox').removeAttr('checked');
        $('.data2-checkbox:checkbox').removeAttr('checked');
        $('.data3-checkbox:checkbox').removeAttr('checked');
        $('.page').hide();
    })

    //弹出练车时间的信息框
    function clicklcsj(e) {
        $('#modal-overlay').css('visibility', 'visible')
        $('.modal-data3').css('visibility', 'visible')
        $('.data3-checkbox:checkbox').removeAttr('checked');
        $.ajax({
            url: '<%=path5%>/DrivingSys/getExerciseCarPlan ',
            type: "post",
            data: {
                'pindex': '0'
            },
            dataType: "json",
            success: function (res) {
                $('#cartimeList').html(myTemplatcartime(res));
                $('#totalPage3').val(res.pb3);
            },
            error: function () {
                alert('Error');
            }
        });
        $('.page').show();
        _this = e;
    }

    //根据车型科目查询教练
    function selectPersonList() {
        carType = $('.carType').val();
        kemu = $('.kemu').val();
        //$('#studebntList').html("<div class='loading'></div>");
        $.ajax({
            url: '<%=path2%>/DrivingSys/selectPersonList',
            type: "post",
            data: {
                'carType': carType,
                'kemu': kemu
            },
            dataType: "json",
            success: function (res) {
                $('.ty-tree-select1').html(jlList(res));
                $('#ued-transfer-1').transferItem();
            },
            error: function () {
                alert('Error');
            }
        });
    }

    $(".number").live('keyup', function (event) {
        //最后一位是小数点的话，移除
        var $amountInput = $(this);
        //响应鼠标事件，允许左右方向键移动
        event = window.event || event;
        if (event.keyCode == 37 | event.keyCode == 39) {
            return;
        }
        var clazz = $(this).prop("class")
        //获取输入框的值
        var value = $('.' + clazz + '').val();
        //判断负数是否在第一位
        if (value.substring(0, 1) == '-') {

        }
        if (value.length == 0) {
            $(this).val("0")
        }
        if (value.lastIndexOf('0') == 0) {
            $(this).val(value.substring(1, value.length))
            // $amountInput.val($amountInput.val().replace('-','')
        }
        //判断负数不是在第一位，替换
        if (value.lastIndexOf('-') >= 0) {
            $('.' + clazz + '').val("0")
            // $amountInput.val($amountInput.val().replace('-','')
        }
        //先把非数字的都替换掉，除了数字和.
        $amountInput.val($amountInput.val().replace(/[^\-?\d]/g, "").//只允许一个小数点
        replace(/^\./g, "").replace(/\.{2,}/g, ".").//只能输入小数点后两位
        replace(".", "$#$").replace(/\./g, "").replace("$#$", ".").replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'));
        if ($(this).val() == "") {
            $(this).val(0)
        }
    });


</script>
<%@ include file="/WEB-INF/JSP/ajax.jsp" %>
</html>